package com.ljx.controller;


import com.ljx.R;
import com.ljx.pojo.subject.OneSubject;
import com.ljx.service.impl.EduSubjectServiceImpl;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author 李加喜
 * @since 2020-09-24
 */
@Api(description = "课程分类添加模块")
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {
    @Autowired
    private EduSubjectServiceImpl eduSubjectService;
    //添加课程分类
    //获取上传的文件  读取文件地内容
    @PostMapping("/addSubject")
    public R addSubject(MultipartFile file){
        //获取上传过来的Excel的文件  将其保存在到数据库里面
        eduSubjectService.saveSubject(file,eduSubjectService);
        //eduSubjectService.saveSubject(multipartFile);
        return R.ok();
    }
    //课程分类功能的列表显示
    //难点 返回指定格式的数据

    /**
     * {
     * id: 1,
     * label: '1级分类',
     * children: [{
     * id: 4,
     * label: '一级分类1',
     * }, {
     *  id: 2,
     *  label: '二级分类',
     *  children: [{
     *  id: 5,
     *  label: '二级分类-1'
     *   },
     *   {
     *   d: 6,
     *    label: '二级分类-2'
     *   }]}
     * @return
     */
    @GetMapping("/findAll")
    public R getSubject(){
        //返回1 2 级的集合
        List<OneSubject> list=eduSubjectService.getAllOneSubject();
        return R.ok().data("list",list);
    }
}

